<?php
/**
 * Ajax操作类
 * @author yaoli<yaoli@pateo.com.cn>
 * @version 1.0 GetUser add by yaoli<yaoli@pateo.com.cn> 
 */
class test extends ActionBase {
	
	private $date = null;
	
	function init() {
	
	}
	
	/**
	 * 动作
	 *
	 * @see AActionBase::action()
	 */
	public function action() {
		error_reporting(E_ALL);
		$json = get_url_content('http://map.sogou.com/lushu/lushu/getTrackJson/c8808035251312a60125149d703f0070');
		$json = get_url_content('http://map.sogou.com/lushu/lushu/getTrackJson/9a8080ac2180133001218137c6370346');
		#echo "<br>";echo "<br>";echo "<br>";echo "<br>";echo "<br>";
		 $json = iconv("GB2312//IGNORE", "UTF-8", str_replace("'", '"', $json));
		
		$arr = json_decode($json);
		
		 json_last_error();
		dump($arr);exit;
	}
	
	public function phpinfo(){echo phpinfo();}
	
	private function hello(){}
	
	public function Reflection(){
		get_class_all_methods(test,1);
	}
	
	//缓存输出
	public function danguang(){
		header("Content-type: multipart/x-mixed-replace;boundary=endofsection");
		print "--endofsection\n";
		$pmt = array("-", "\\", "|", "/" );
		for( $i = 0; $i <10;$i ++ )
		{
			sleep(1);
			print "Content-type: text/plain\n\n";
			print "Part $i     ".$pmt[$i % 4];
			print "--endofsection\n";
			ob_flush(); //强制将缓存区的内容输出
			flush(); //强制将缓冲区的内容发送给客户端
		}
		print "Content-type: text/plain\n\n";
		print "The end\n";
		print "–endofsection–\n";
	}
	
	public function index(){
		
		$rbid = 'hzdyj20090331161815';
		
		
		$site_url = 'http://lushu.51ditu.com';
		
		$json = get_url_content($site_url.'/routebook/rbinfo.do?method=rbInfo&rbid='.$rbid);
		$json = iconv("GBK", "UTF-8", str_replace("'", '"', $json));
		
		
		preg_match('/<td style="word-break:break-all;">([\s\S]*?)<\/iframe>/', $json, $matchess);
		
		//获取路书名称
		preg_match('/<b>([\s\S]*?)<\/b>/', $matchess[1], $title);
		$this->date['roadbook_name']=($title[1]);
		
		'<br>
       
		作者：hzdyj<br/>';
		//获取路书作者
		preg_match('/<br>\s*\n*\s*作者：(.*?)<br\/>/', $matchess[1], $author);
		$authorstr = preg_replace('/\\r\\n/', '', $author[1]);
		$authorstr = str_replace(' ', '', $authorstr);
		$this->date['author_name']=trim($authorstr);
		
		
		//获取路书里程
		preg_match('/<br\/>\s+\n+\s+里程：(.*?)公里<br\/>/', $matchess[1], $kilometers);
		
		
	
		$kilo = preg_replace('/\\r\\n/', '', $kilometers[1]);
		$this->date['kilometers']=trim($kilo);
		
		//获取路书行程
		preg_match('/<td>([\s\S]*?[\s\S])<\/td>\s+\n\s+<td align="right"><img src="\/img\/dl.gif">/', $matchess[1], $journey);
		#$jour = preg_replace('/\\r\\n/', '', $journey[1]);
		$this->date['journey']=trim($journey[1]);
		
		//获取路书描述
		preg_match('/<\/table>([\s\S]*?[\s\S])<br><br>/', $matchess[1], $journey);
		$this->date['introduction']=trim($journey[1]);
		
		
		/**
		 * IFRAME框中的采集途径地 途径点兴趣点信息
		 */
		preg_match('/<iframe[^>]+src="(.*)">/', $matchess[1], $array);
		$iframeurl = $site_url.$array[1];
		$iframe = get_url_content($iframeurl);
		$iframe = iconv("GBK", "UTF-8", str_replace("'", '"', $iframe));
		
		//采集途径地内容 
		preg_match_all('/sign\.push\({n\:\d+\,lng\:\d+\,lat\:\d+\,t\:\"(.*?)\"\,c\:\"/', $iframe, $arraytj);
		
		//途径地图片
		preg_match_all('/signImg\.push\( \"(.*?)\" \)\;/', $iframe, $arraytjimg);
		
		//途径地描述
		preg_match_all('/<div id=\"sScrol.*?<\/div>\s*\n\s*(.*?)\n*\s*<\/td>/', $iframe, $arraydes);
		
		/* dump($arraytj[1]);
		dump($arraytjimg[1]);
		dump($arraydes[1]); */
		
		
		foreach($arraytj[1] as $key=>$value){
			$this->date['way'][$key]['name'] = $value;
			$this->date['way'][$key]['pic'] = $arraytjimg[1][$key];
			$this->date['way'][$key]['introduction'] = $arraydes[1][$key];
		}
		
	
		
		
		//采集兴趣点内容
		preg_match_all('/pois\.push\({n\:\d+\,lng\:\d+\,lat\:\d+\,t\:\"(.*?)\"\,c\:\"/', $iframe, $arrayxq);
		
		//兴趣点图片
		preg_match_all('/poisImg\.push\( \"(.*?)\" \)\;/', $iframe, $arrayxqimg);
		
		//兴趣点描述
		preg_match_all('/<div id=\"pScrol.*?<\/div>\s*\n\s*(.*?)\s*<\/td>/', $iframe, $arrayname2);
		
		/*  dump($arrayxq[1]);
		dump($arrayxqimg[1]); 
		dump($arrayname2[1]); */
		
		foreach($arrayxq[1] as $key=>$value){
			$this->date['point'][$key]['name'] = $value;
			$this->date['point'][$key]['pic'] = $arrayxqimg[1][$key];
			$this->date['point'][$key]['introduction'] = $arrayname2[1][$key];
		}
		
		
		dump($this->date);
		echo $iframe;
		
	}
	
	function mst(){
		$str='why?
		No why!
		why no why?
		No why no why!';
		$ar = (explode(chr(13),$str));
		dump($ar[1]);
		dump($str);
	}
	
	function ZZ(){
		preg_match('#(?P<action>\w+)#', '/中国话/dfsadf', $matches);
		var_dump($matches);
	}
		
	
	

}